package com.lagou.springboot_homework.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lagou.springboot_homework.pojo.TArticle;
import com.lagou.springboot_homework.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.security.PublicKey;
import java.util.List;

@Controller
public class ArticleController {
    @Autowired
    private ArticleService articleService;

//    @GetMapping("/getAllPerson")
//    public String getAllPerson(Model model,@RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum){
//        PageHelper.startPage(pageNum,5);
//        List<Person> list = personService.getAllPerson();
//        PageInfo<Person> pageInfo = new PageInfo<Person>(list);
//        model.addAttribute("pageInfo",pageInfo);
//        return "client/index";
//    }

    @GetMapping("/getAll")
    public String getArticles(Model model ,@RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum){

        PageHelper.startPage(pageNum,2);
        List<TArticle> list = articleService.getAll();
        PageInfo<TArticle> pageInfo = new PageInfo<TArticle>(list);
        model.addAttribute("pageInfo",pageInfo);

        return "client/index";
    }

}
